import urllib.request
import re

def maoyan(url):
        res=urllib.request.urlopen(url)
        html=res.read().decode("utf-8")

        pattern = re.compile('<dd>.*?board-index.*?>(\d+)</i>.*?data-src="(.*?)".*?name"><a'
                                 + '.*?>(.*?)</a>.*?star">(.*?)</p>.*?releasetime">(.*?)</p>'
                                 + '.*?integer">(.*?)</i>.*?fraction">(.*?)</i>.*?</dd>', re.S)
            # findall()使用正则表达式
        items = re.findall(pattern,html)
            # 遍历列表以字典的形式输出
        for item in items:
          print(item[0],"图片"+":"+item[1],"电影名称"+":"+item[2],"主演"+":"+item[3].strip()[3:],"时间"+":"+item[4].strip()[5:],"评分"+":"+item[5]+item[6])

if __name__=="__main__":
         url = 'http://maoyan.com/board/4?offset=0'
         maoyan(url)
         offset=10
         for i in range(10):
                url = 'http://maoyan.com/board/4?offset=' +str(offset)
                maoyan(url)
                offset+=10
